local qingche = fk.CreateSkill {
  name = "emo__qingche",
}

qingche:addEffect("active", {
  anim_type = "control",
  times = function (self, player)
    return 2 - player:usedSkillTimes(qingche.name, Player.HistoryPhase)
  end,
  can_use = function(self, player)
    return player:usedSkillTimes(qingche.name, Player.HistoryPhase) < 2
  end,
  card_num = 0,
  card_filter = Util.FalseFunc,
  interaction = function (self, player)
    local all_choices = {"#emo__qingche_other", "#emo__qingche_draw"}
    local choices = {all_choices[1]}
    if player:getHandcardNum() < player.maxHp then
      table.insert(choices, all_choices[2])
    end
    return UI.ComboBox { choices = choices, all_choices = all_choices}
  end,
  target_filter = function (self, player, to, selected, selected_cards)
    if self.interaction.data == "#emo__qingche_other" then
      return #selected == 0 and to ~= player and to:getHandcardNum() ~= to.hp
    end
  end,
  feasible = function (self, player, selected, selected_cards, card)
    if self.interaction.data == "#emo__qingche_other" then
      return #selected == 1
    else
      return player:getHandcardNum() < player.maxHp
    end
  end,
  on_use = function(self, room, use)
    local player = use.from
    if #use.tos > 0 then
      local to = use.tos[1]
      local x = to:getHandcardNum() - to.hp
      if x > 0 then
        room:askToDiscard(to, {min_num = x, max_num = x, include_equip = false, cancelable = false, skill_name = qingche.name})
      elseif x < 0 then
        to:drawCards(-x, qingche.name)
      end
    else
      local y = player.maxHp - player:getHandcardNum()
      if y > 0 then
        player:drawCards(y, qingche.name)
      end
    end
  end,
})


Fk:loadTranslationTable{
  ["emo__qingche"] = "擎掣",
  [":emo__qingche"] = "出牌阶段限两次。你可以选一项：<br>1.令一名其他角色将手牌数调整至其体力值。<br>2.将你的手牌摸至体力上限。",
  ["#emo__qingche_other"] = "令其他角色将手牌调整至体力值",
  ["#emo__qingche_draw"] = "将你的手牌摸至体力上限",
}

return qingche
